package prj5;

import student.TestCase;
import student.testingsupport.annotations.Hint;

import java.util.ArrayList;
import java.util.List;

/**
 * Test Database class.
 * @author xinruili
 * @version 1.0
 */
public class DataTest extends TestCase {
    private Data data;
    private RaceStatusData race;
    private RaceStatusData otherRace;

    /**
     * sets up any needed variables for test methods.
     * @throws Exception sets up variables
     * @author xinruili
     * @version 1.0
     */
    @Override
    public void setUp() throws Exception {
        super.setUp();
        data = new Data("Dc");
        race = new RaceStatusData("racename",
                "120", "30");
        otherRace = new RaceStatusData("other",
                "120", "40");
        data.addRace(otherRace);
        data.addRace(race);
    }

    /**
     * testAddRace.
     */
    @Hint("AddRace is error!")
    public void testAddRace() {
        assertEquals(data.getRaceOfStateData()
                .indexOf(otherRace), 0);
        assertEquals(data.getRaceOfStateData()
                .indexOf(race), 1);
    }

    /**
     * testGetRaceSortByCFR.
     */
    @Hint("GetRaceSortByCFR is error!")
    public void testGetRaceSortByCFR() {
        List<RaceStatusData> races = new ArrayList<>();
        races.add(otherRace);
        races.add(race);
        assertEquals(races, data.getRaceSortByCFR());
    }

    /**
     * testGetRaceSortByCFR.
     */
    @Hint("GetRaceSortByAipha is error!")
    public void testGetRaceSortByAipha() {
        List<RaceStatusData> races = new ArrayList<>();
        races.add(otherRace);
        races.add(race);
        assertEquals(races, data.getRaceSortByAipha());
    }

    /**
     * testGetRaceSortByCFR.
     */
    @Hint("ShowSout is error!")
    public void testShowSout() {
        data.showSout();
        String soutData = "other: 120 cases, 33.3% CFR\n"
                + "racename: 120 cases, 25% CFR\n"
                + "=====\n"
                + "other: 120 cases, 33.3% CFR\n"
                + "racename: 120 cases, 25% CFR\n"
                + "=====\n";
        assertEquals(systemOut().getHistory(), soutData);
    }

    /**
     * testGetStateName.
     */
    @Hint("GetStateName is error!")
    public void testGetStateName() {
        assertEquals("Dc", data.getStateName());
    }
}
